package com.mofang.activity.recommend;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.mofang.R;
import com.mofang.activity.BaseTitleViewActiviey;

public class AllRecommendedDetails extends BaseTitleViewActiviey {

	private ListView all_recommended_details_list;
	private AllRecommendedDetailsAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initView() {
		setContentView(R.layout.activity_all_recommended_details);
		setNavigationLeftBtnImage(R.drawable.return_arrow);
		setNavigationTitle("全部推荐信息");
		adapter = new AllRecommendedDetailsAdapter(getApplicationContext());
		all_recommended_details_list = (ListView) findViewById(R.id.all_recommended_details_list);
		all_recommended_details_list.setAdapter(adapter);
		all_recommended_details_list
				.setOnItemClickListener(new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) {
						Intent intent = new Intent(getApplicationContext(),
								ScheduleDetailsActivity.class);
						intent.putExtra("AllRecommendedDetailsTag",
								"AllRecommendedDetailsTag");
						startActivity(intent);
					}
				});
	}

	public class AllRecommendedDetailsAdapter extends BaseAdapter {

		private LayoutInflater mInflater;
		Context context;
		int count = 10;

		public AllRecommendedDetailsAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
			this.context = context;
		}

		@Override
		public int getCount() {
			return count;
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Holder myHolder;
			if (convertView == null) {
				myHolder = new Holder();
				convertView = mInflater.inflate(
						R.layout.activity_all_recommended_details_list_item,
						null);
				convertView.setTag(myHolder);
			} else {
				myHolder = (Holder) convertView.getTag();
			}
			return convertView;
		}

		class Holder {
			ImageView attachment;
			TextView news_title;
			TextView news_content;
			TextView news_time;
		}
	}
}
